import { defineConfig } from "@playwright/test";
import dotenv from "dotenv";
import path from "path";

// Load environment variables before setting TEST_ENV
dotenv.config();

// Try loading from repo root (packages/core/lib/v3/tests -> repo root = 5 levels up)
const repoRootEnvPath = path.resolve(__dirname, "../../../../../.env");
dotenv.config({ path: repoRootEnvPath, override: false });

// Set TEST_ENV before tests run
process.env.TEST_ENV = "LOCAL";

export default defineConfig({
  testDir: ".",
  timeout: 90_000,
  expect: { timeout: 10_000 },
  // Balanced parallelization: 3 workers in CI to avoid resource exhaustion while maintaining speed.
  // Local development can use more workers for faster test runs.
  workers: process.env.CI ? 3 : 5,
  fullyParallel: true,
  projects: [
    {
      name: "default",
      testIgnore: /shadow-iframe\.spec\.ts$/,
    },
    {
      name: "shadow-iframe",
      testMatch: /shadow-iframe\.spec\.ts$/,
      workers: 2,
      fullyParallel: true,
    },
  ],
  reporter: "list",
  use: {
    // we're not launching Playwright browsers in these tests; we connect via Puppeteer/CDP to V3.
    headless: false,
  },
});
